using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLRZUORD
    {
        public DataRow Convert2LRZUORD(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLRZUORD(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LRZMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LRZREZART"] = " ".PadRight(1 ); 
         dwReturn["LRZREZNR"] = " ".PadRight(10 ); 
         dwReturn["LRZREZST"] = " ".PadRight(1 ); 
         dwReturn["LRZREZPOS"] = " ".PadRight(4 ); 
         dwReturn["LRZAENZL"] = " ".PadRight(0 ); 
         dwReturn["LRZAENB"] = " ".PadRight(8 ); 
         dwReturn["LRZAEND"] = " ".PadRight(0 ); 
         dwReturn["LRZNEUB"] = " ".PadRight(8 ); 
         dwReturn["LRZNEUD"] = " ".PadRight(0 ); 
         dwReturn["LRZVSTUFE"] = " ".PadRight(1 ); 
         dwReturn["LRZKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["LRZWERK"] = " ".PadRight(3 ); 
         dwReturn["LRZABT"] = " ".PadRight(3 ); 
         dwReturn["LRZWAKZ"] = " ".PadRight(1 ); 
         dwReturn["LRZART"] = " ".PadRight(20 ); 
         dwReturn["LRZVAR"] = " ".PadRight(3 ); 
         dwReturn["LRZFARBE"] = " ".PadRight(10 ); 
         dwReturn["LRZDESS"] = " ".PadRight(10 ); 
         dwReturn["LRZCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["LRZBESCHICH"] = " ".PadRight(10 ); 
         dwReturn["LRZZUSTAND"] = " ".PadRight(4 ); 
         dwReturn["LRZSUBSTR"] = " ".PadRight(15 ); 
         dwReturn["LRZAGANG"] = " ".PadRight(15 ); 
         dwReturn["LRZMODNR"] = " ".PadRight(3 ); 
         dwReturn["LRZMTYP"] = " ".PadRight(8 ); 
         dwReturn["LRZFLOAUF"] = " ".PadRight(0 ); 
         dwReturn["LRZFLOAUFM"] = " ".PadRight(1 ); 
         dwReturn["LRZVCODE"] = " ".PadRight(15 ); 
         dwReturn["LRZFILLER"] = " ".PadRight(32 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLRZUORD(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLRZUORD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLRZUORD(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLRZUORD(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLRZUORD(dwLocal, ITXDBVERSION);
            }
            UpdateLRZUORD(dwLocal);
        }
        public void InsertLRZUORD(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LRZUORD(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLRZUORD(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LRZUORD WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LRZUORD  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LRZUORD";
            Return = Result;
            return Return;
        }
        public void DeleteLRZUORD(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LRZUORD   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLRZUORD(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LRZUORD SET "
                    +"LRZMANDANT= :LRZMANDANT,"
                    +"LRZREZART= :LRZREZART,"
                    +"LRZREZNR= :LRZREZNR,"
                    +"LRZREZST= :LRZREZST,"
                    +"LRZREZPOS= :LRZREZPOS,"
                    +"LRZAENZL= :LRZAENZL,"
                    +"LRZAENB= :LRZAENB,"
                    +"LRZAEND= :LRZAEND,"
                    +"LRZNEUB= :LRZNEUB,"
                    +"LRZNEUD= :LRZNEUD,"
                    +"LRZVSTUFE= :LRZVSTUFE,"
                    +"LRZKUNDNR= :LRZKUNDNR,"
                    +"LRZWERK= :LRZWERK,"
                    +"LRZABT= :LRZABT,"
                    +"LRZWAKZ= :LRZWAKZ,"
                    +"LRZART= :LRZART,"
                    +"LRZVAR= :LRZVAR,"
                    +"LRZFARBE= :LRZFARBE,"
                    +"LRZDESS= :LRZDESS,"
                    +"LRZCOLORIT= :LRZCOLORIT,"
                    +"LRZBESCHICH= :LRZBESCHICH,"
                    +"LRZZUSTAND= :LRZZUSTAND,"
                    +"LRZSUBSTR= :LRZSUBSTR,"
                    +"LRZAGANG= :LRZAGANG,"
                    +"LRZMODNR= :LRZMODNR,"
                    +"LRZMTYP= :LRZMTYP,"
                    +"LRZFLOAUF= :LRZFLOAUF,"
                    +"LRZFLOAUFM= :LRZFLOAUFM,"
                    +"LRZVCODE= :LRZVCODE,"
                    +"LRZFILLER= :LRZFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LRZMANDANT", OracleType.NVarChar).Value = dwData["LRZMANDANT"].ToString(); 
          or1.Parameters.Add("LRZREZART", OracleType.NVarChar).Value = dwData["LRZREZART"].ToString(); 
          or1.Parameters.Add("LRZREZNR", OracleType.NVarChar).Value = dwData["LRZREZNR"].ToString(); 
          or1.Parameters.Add("LRZREZST", OracleType.NVarChar).Value = dwData["LRZREZST"].ToString(); 
          or1.Parameters.Add("LRZREZPOS", OracleType.NVarChar).Value = dwData["LRZREZPOS"].ToString(); 
          or1.Parameters.Add("LRZAENZL", OracleType.NVarChar).Value = dwData["LRZAENZL"].ToString(); 
          or1.Parameters.Add("LRZAENB", OracleType.NVarChar).Value = dwData["LRZAENB"].ToString(); 
          or1.Parameters.Add("LRZAEND", OracleType.NVarChar).Value = dwData["LRZAEND"].ToString(); 
          or1.Parameters.Add("LRZNEUB", OracleType.NVarChar).Value = dwData["LRZNEUB"].ToString(); 
          or1.Parameters.Add("LRZNEUD", OracleType.NVarChar).Value = dwData["LRZNEUD"].ToString(); 
          or1.Parameters.Add("LRZVSTUFE", OracleType.NVarChar).Value = dwData["LRZVSTUFE"].ToString(); 
          or1.Parameters.Add("LRZKUNDNR", OracleType.NVarChar).Value = dwData["LRZKUNDNR"].ToString(); 
          or1.Parameters.Add("LRZWERK", OracleType.NVarChar).Value = dwData["LRZWERK"].ToString(); 
          or1.Parameters.Add("LRZABT", OracleType.NVarChar).Value = dwData["LRZABT"].ToString(); 
          or1.Parameters.Add("LRZWAKZ", OracleType.NVarChar).Value = dwData["LRZWAKZ"].ToString(); 
          or1.Parameters.Add("LRZART", OracleType.NVarChar).Value = dwData["LRZART"].ToString(); 
          or1.Parameters.Add("LRZVAR", OracleType.NVarChar).Value = dwData["LRZVAR"].ToString(); 
          or1.Parameters.Add("LRZFARBE", OracleType.NVarChar).Value = dwData["LRZFARBE"].ToString(); 
          or1.Parameters.Add("LRZDESS", OracleType.NVarChar).Value = dwData["LRZDESS"].ToString(); 
          or1.Parameters.Add("LRZCOLORIT", OracleType.NVarChar).Value = dwData["LRZCOLORIT"].ToString(); 
          or1.Parameters.Add("LRZBESCHICH", OracleType.NVarChar).Value = dwData["LRZBESCHICH"].ToString(); 
          or1.Parameters.Add("LRZZUSTAND", OracleType.NVarChar).Value = dwData["LRZZUSTAND"].ToString(); 
          or1.Parameters.Add("LRZSUBSTR", OracleType.NVarChar).Value = dwData["LRZSUBSTR"].ToString(); 
          or1.Parameters.Add("LRZAGANG", OracleType.NVarChar).Value = dwData["LRZAGANG"].ToString(); 
          or1.Parameters.Add("LRZMODNR", OracleType.NVarChar).Value = dwData["LRZMODNR"].ToString(); 
          or1.Parameters.Add("LRZMTYP", OracleType.NVarChar).Value = dwData["LRZMTYP"].ToString(); 
          or1.Parameters.Add("LRZFLOAUF", OracleType.NVarChar).Value = dwData["LRZFLOAUF"].ToString(); 
          or1.Parameters.Add("LRZFLOAUFM", OracleType.NVarChar).Value = dwData["LRZFLOAUFM"].ToString(); 
          or1.Parameters.Add("LRZVCODE", OracleType.NVarChar).Value = dwData["LRZVCODE"].ToString(); 
          or1.Parameters.Add("LRZFILLER", OracleType.NVarChar).Value = dwData["LRZFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
